package com.tgjorgoski.utils;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ColorButton extends JButton implements Icon, ActionListener {
	private Color color;

	private int iconw, iconh;

	public ColorButton(Color color, String name, int iconw, int iconh) {
		this.color = color;
		this.iconw = iconw;
		this.iconh = iconh;
		setToolTipText(name);
		setIcon(this);
		addActionListener(this);
	}
	
	public Color getTheColor() {
		return color;
	}

	public void setTheColor(Color color) {
		this.color = color;
		repaint();
	}

	public void actionPerformed(ActionEvent e) {
	}

	// Icon methods
	public int getIconWidth() {
		return iconw;
	}

	public int getIconHeight() {
		return iconh;
	}

	public void paintIcon(Component c, Graphics g, int x, int y) {
		Color old = g.getColor();
		g.setColor(color);
		g.fillRect(x, y, iconw, iconh);
		g.setColor(old);
	}
}
